﻿package org.xhs.report
{
    import baidu.ui.managers.*;
    import baidu.wenku.common.*;
    import baidu.wenku.common.adv.*;
    import baidu.wenku.common.model.*;
    import baidu.wenku.common.utils.*;
    import flash.display.*;
    import flash.external.*;
    import flash.utils.*;

    public class Main extends Sprite
    {
        protected var mainStage:Stage;
        protected var fpsMemCounter:FPSMemCounter;

        public function Main()
        {
            return;
        }// end function

        public function init(param1:Stage) : void
        {
            this.mainStage = param1;
            CursorManager.getInstance().root = this.mainStage;
            TooltipManager.getInstance().root = this.mainStage;
            this.initDebug();
            this.initLocale();
            this.initConfig();
            this.initModel();
            this.initReader();
            this.initCounter();
            this.initTestVersion();
            this.initAdv();
            return;
        }// end function

        protected function initDebug() : void
        {
            Logger.enabled = true;
            Logger.errorEnabled = true;
            Logger.debugEnabled = false;
            Logger.debug(this.getVersion());
            return;
        }// end function

        protected function initLocale() : void
        {
            return;
        }// end function

        protected function initConfig() : void
        {
            Config.docType = "doc" ? ("doc") : (Config.DOC_TYPE_DOC);
            return;
        }// end function

        protected function initModel() : void
        {
            var _loc_1:LoaderInfoVO = null;
            _loc_1 = InstanceManager.createSingletonInstance(LoaderInfoVO);
            _loc_1.init(this.mainStage.loaderInfo);
            var _loc_2:* = InstanceManager.createSingletonInstance(ScreenModel);
            _loc_2.stage = this.mainStage;
            return;
        }// end function

        protected function initReader() : void
        {
            var _loc_1:Class = null;
            var _loc_2:Object = null;
            switch(Config.docType)
            {
                case Config.DOC_TYPE_TXT:
                {
                    _loc_1 = getDefinitionByName("baidu.wenku.txt.TxtMain") as Class;
                    break;
                }
                default:
                {
                    _loc_1 = getDefinitionByName("baidu.wenku.doc.DocMain") as Class;
                    break;
                    break;
                }
            }
            if (_loc_1 != null)
            {
                _loc_2 = new _loc_1;
                addChild(_loc_2 as DisplayObject);
            }
            return;
        }// end function

        protected function initAdv() : void
        {
            var _loc_1:* = new AdvBuffer(stage);
            return;
        }// end function

        protected function initCounter() : void
        {
            this.fpsMemCounter = new FPSMemCounter();
            this.fpsMemCounter.visible = false;
            this.fpsMemCounter.alpha = 0.6;
            addChild(this.fpsMemCounter);
            return;
        }// end function

        protected function initTestVersion() : void
        {
            try
            {
                ExternalInterface.addCallback("ver", this.getVersion);
                ExternalInterface.addCallback("fps", this.showFPS);
                ExternalInterface.addCallback("debug", this.enableDebug);
            }
            catch (e:Error)
            {
            }
            return;
        }// end function

        protected function showFPS() : void
        {
            if (this.fpsMemCounter)
            {
                this.fpsMemCounter.visible = true;
            }
            return;
        }// end function

        protected function enableDebug(param1:Boolean = true) : void
        {
            Logger.enabled = param1;
            Logger.debugEnabled = param1;
            return;
        }// end function

        protected function getVersion() : String
        {
            return "wenku_flash_builder, 2011-06-16, share_icon";
        }// end function

    }
}
